package com.jesterplayer;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever;
import android.util.Log;

public class CurrentTrack {
	private static String path;
	private static Bitmap albumArt;
	private static String album;
	private static String artist;
	private static String title;
	private static MediaMetadataRetriever mmr = new MediaMetadataRetriever();
	
	
	public CurrentTrack(String path){
		
		CurrentTrack.path = path;
		//MediaMetadataRetriever mmr = new MediaMetadataRetriever();
		
		mmr.setDataSource(path);
		
		albumArt = BitmapFactory.decodeByteArray(mmr.getEmbeddedPicture(),0,mmr.getEmbeddedPicture().length);
		
		album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
		artist = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
		title = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
		
	}
	
	
	public void setCurrentTrack(String path){
		
		CurrentTrack.path = path;
	
		//mmr.release();
		
		Log.d("path", path);
		mmr.setDataSource(path);
		byte[] albumArtArray = mmr.getEmbeddedPicture();
		if(albumArtArray!=null){
			albumArt = BitmapFactory.decodeByteArray(albumArtArray,0,mmr.getEmbeddedPicture().length);
		}
		else{
			albumArt = null;
		}
		album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
		artist = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
		title = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
		
	}


	public static String getPath() {
		return path;
	}


	public static void setPath(String path) {
		CurrentTrack.path = path;
	}


	public static Bitmap getAlbumArt() {
		return albumArt;
	}


	public static void setAlbumArt(Bitmap albumArt) {
		CurrentTrack.albumArt = albumArt;
	}


	public static String getAlbum() {
		return album;
	}


	public static void setAlbum(String album) {
		CurrentTrack.album = album;
	}


	public static String getArtist() {
		return artist;
	}


	public static void setArtist(String artist) {
		CurrentTrack.artist = artist;
	}


	public static String getTitle() {
		return title;
	}


	public static void setTitle(String title) {
		CurrentTrack.title = title;
	}
	
	
	

}
